using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TradeFlow.Server.Service;
using TradeFlow.Server.Dto;
using TradeFlow.Server.Models;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using TradeFlow.Server.Language;
using System.Reflection;

namespace TradeFlow.Web.Controllers
{
    /// <summary>
    /// 业务单表头控制器
    /// </summary>
    [Authorize]
    public class JxBillHeadController : Controller
    {
        private readonly JxBillHeadService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public JxBillHeadController(JxBillHeadService service)
        {
            _service = service;
        }

        /// <summary>
        /// 业务单管理首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 查询业务单表头分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetPages([FromBody] JxBillHeadPageParam param)
        {
            var result = await _service.GetPagesAsync(param);
            return Json(result);
        }

        /// <summary>
        /// 获取所有业务单表头列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetList()
        {
            var result = await _service.GetListAsync();
            return Json(result);
        }

        /// <summary>
        /// 根据ID获取业务单表头
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetById(long id)
        {
            var result = await _service.GetByIdAsync(id);
            return Json(result);
        }

        /// <summary>
        /// 增加业务单表头
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add([FromBody] JxBillHead entity)
        {
            var result = await _service.AddAsync(entity);
            return Json(result);
        }

        /// <summary>
        /// 更新业务单表头
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update([FromBody] JxBillHead entity)
        {
            var result = await _service.UpdateAsync(entity);
            return Json(result);
        }

        /// <summary>
        /// 删除业务单表头
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> Delete([FromBody] List<long> ids)
        {
            var result = await _service.DeleteAsync(ids);
            return Json(result);
        }

        /// <summary>
        /// 提交业务单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Submit(long id)
        {
            var result = await _service.SubmitAsync(id);
            return Json(result);
        }

        /// <summary>
        /// 复制业务单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Copy(long id)
        {
            var result = await _service.CopyAsync(id);
            return Json(result);
        }
    }
}